package com.smart.home.mapper;

import com.smart.home.controller.Devices.DevicesTypeController;

import com.smart.home.entity.DeviceTypes;
import com.smart.home.entity.Devices;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface DeviceTypeMapper {


    @Insert("insert into smarthome.device_types(type_code,type_name,description) values(#{typeCode},#{typeName},#{description})")
    @Options(useGeneratedKeys = true, keyProperty = "id")
    void addDevice(DeviceTypes deviceTypes);

    void updateDevice(DeviceTypes deviceTypes, Long id);

    @Select("Select DISTINCT t.* from smarthome.device_types t join smarthome.devices d on d.type_id = t.id where d.home_id = #{homeId}")
    List<DeviceTypes> queryDeviceTypes(Long homeId);

    @Delete("delete from smarthome.device_types where id = #{id}")
    void removeDeviceType(Long id);

    @Select("SELECT d.id FROM smarthome.devices d JOIN smarthome.device_types t ON d.type_id = t.id WHERE t.id = #{id}")
    List<Long> getDevices(Long id);
}
